<?php
/**
* $Id$
* @author Hung Nguyen, Flexica Solutions
* Class ApplicationUser
*/
class ApplicationUser extends CWebUser
{
    const ROLE_GUESTS           = 'guest';
    const ROLE_USERS            = 'user';
    const ROLE_ADMINISTRATORS   = 'administrator';
    /**
    * Check if user has a specific role
    * 
    * @param string $role
    * @return bool
    */
    public function isInRole($role){
        //Fixed role 'guest'. 
        /**
        * As the purpose of this function is to check if user has permssion to do something
        * and a user always has all the guest permission, we return TRUE in this case.
        */
        if (strtolower($role) == self::ROLE_GUESTS)
            return true;
            
        //Fixed role 'users'
        if (strtolower($role) == self::ROLE_USERS)
            return !$this->getIsGuest();
            
        //Any other role, first we check if it's specifically assigned to user
        /*if (array_search($role, $this->getState('Roles', array())) !== false)
            return true;*/
        if (in_array($role,$this->getState('Roles', array()))) return true;
        
        return false;
    }
}
?>